import request from '@/utils/request'
import { getToken } from '@/utils/auth'

const bURL = 'http://10.61.22.44:8889/brother_hood/backstage/public/classification/'
const token = getToken()

/*
  获取一级分类，包含着相应的二级分类
 */
export function getFirCla() {
  return request({
    baseURL: bURL,
    url: 'gfc',
    method: 'get',
    params: {}
  })
}

/*
  添加一级分类
 */
export function addFirCla(name) {
  const token = getToken()
  return request({
    baseURL: bURL,
    url: 'afc',
    method: 'post',
    headers: {
      'Authorization': 'Bearer ' + token
    },
    params: {
      'name': name
    }
  })
}

/*
  删除一级分类
 */
export function delFirCla(id) {
  return request({
    baseURL: bURL,
    url: 'dfc',
    method: 'delete',
    headers: {
      'Authorization': 'Bearer ' + token
    },
    params: {
      'id': id
    }
  })
}

/*
  更新一级分类
 */
export function updFirCla(updateForm) {
  return request({
    baseURL: bURL,
    url: 'ufc',
    method: 'put',
    headers: {
      'Authorization': 'Bearer ' + token
    },
    params: updateForm
  })
}

/*
  添加二级分类
 */
export function addSecCla(addForm) {
  return request({
    baseURL: bURL,
    url: 'asc',
    method: 'post',
    headers: {
      'Authorization': 'Bearer ' + token
    },
    params: addForm
  })
}

/*
  删除二级分类
 */
export function delSecCla(id) {
  return request({
    baseURL: bURL,
    url: 'dsc',
    method: 'delete',
    headers: {
      'Authorization': 'Bearer ' + token
    },
    params: {
      'id': id
    }
  })
}

/*
  更新二级分类
 */
export function updSecCla(updateForm) {
  return request({
    baseURL: bURL,
    url: 'usc',
    method: 'put',
    headers: {
      'Authorization': 'Bearer ' + token
    },
    data: updateForm
  })
}
